﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;

using ConstructionBidOnline.DAL;
using ConstructionBidOnline.DAL.dsJobTableAdapters;
using ConstructionBidOnline.Common;

namespace ConstructionBidOnline.Biz
{
    /// <summary>
    /// Job Business Object
    /// </summary>

    public class Job : BOBase
    {


        #region Construction / Disposal

        /// <summary>
        /// Default constructor.
        /// </summary>
        protected Job() { }

        #endregion

        #region Public Properties

        #region Instance Properties

        /// <summary>
        /// JobID.
        /// </summary>
        public string JobID
        {
            get { return _jobid; }
            set
            {
                if (_jobid != value)
                {
                    if (OnPropertyChanging("JobID", _jobid, value))
                    {
                        string oldValue = _jobid;
                        _jobid = value;
                        OnPropertyChanged("JobID", oldValue, value);
                    }
                }
            }
        }  private string _jobid = null;


        /// <summary>
        /// PKID of the User who is posting the Job.
        /// </summary>
        public int UserID_RK_tblRegisteredUsers
        {
            get { return _userID; }
            set
            {
                if (_userID != value)
                {
                    if (OnPropertyChanging("'UserID_RK_tblRegisteredUsers", _userID, value))
                    {
                        int oldValue = _userID;
                        _userID = value;

                        OnPropertyChanged("'UserID_RK_tblRegisteredUsers", oldValue, value);
                    }
                }
            }
        }  private int _userID = -1;


        /// <summary>
        /// JobTitle.
        /// </summary>
        public string JobTitle
        {
            get { return _jobtitle; }
            set
            {
                if (_jobtitle != value)
                {
                    if (OnPropertyChanging("JobTitle", _jobtitle, value))
                    {
                        string oldValue = _jobtitle;
                        _jobtitle = value;
                        OnPropertyChanged("JobTitle", oldValue, value);
                    }
                }
            }
        }  private string _jobtitle = null;



        /// <summary>
        /// JobFor.
        /// </summary>
        public string JobFor
        {
            get { return _jobfor; }
            set
            {
                if (_jobfor != value)
                {
                    if (OnPropertyChanging("JobFor", _jobfor, value))
                    {
                        string oldValue = _jobfor;
                        _jobfor = value;
                        OnPropertyChanged("JobFor", oldValue, value);
                    }
                }
            }
        }  private string _jobfor = null;


        /// <summary>
        /// JobCategoryName.
        /// </summary>
        public string JobCategoryName
        {
            get { return _jobCategoryName; }
            set
            {
                if (_jobCategoryName != value)
                {
                    if (OnPropertyChanging("JobCategoryName", _jobCategoryName, value))
                    {
                        string oldValue = _jobCategoryName;
                        _jobCategoryName = value;

                        OnPropertyChanged("JobCategoryName", oldValue, value);
                    }
                }
            }
        }  private string _jobCategoryName = null;


        /// <summary>
        /// JobSubCategoryName.
        /// </summary>
        public string JobSubCategoryName
        {
            get { return _jobSubCategoryName; }
            set
            {
                if (_jobSubCategoryName != value)
                {
                    if (OnPropertyChanging("JobSubCategoryName", _jobSubCategoryName, value))
                    {
                        string oldValue = _jobSubCategoryName;
                        _jobSubCategoryName = value;

                        OnPropertyChanged("JobSubCategoryName", oldValue, value);
                    }
                }
            }
        }  private string _jobSubCategoryName = null;



        /// <summary>
        /// JobType.
        /// </summary>
        public string JobType
        {
            get { return _jobtype; }
            set
            {
                if (_jobtype != value)
                {
                    if (OnPropertyChanging("JobType", _jobtype, value))
                    {
                        string oldValue = _jobtype;
                        _jobtype = value;
                        OnPropertyChanged("JobType", oldValue, value);
                    }
                }
            }
        }  private string _jobtype = null;


        /// <summary>
        /// JobDescription.
        /// </summary>
        public string JobDescription
        {
            get { return _jobdescription; }
            set
            {
                if (_jobdescription != value)
                {
                    if (OnPropertyChanging("JobDescription", _jobdescription, value))
                    {
                        string oldValue = _jobdescription;
                        _jobdescription = value;
                        OnPropertyChanged("JobDescription", oldValue, value);
                    }
                }
            }
        }  private string _jobdescription = null;


        /// <summary>
        /// AssociatedDocument.
        /// </summary>
        public string AssociatedDocument
        {
            get { return _associateddocument; }
            set
            {
                if (_associateddocument != value)
                {
                    if (OnPropertyChanging("AssociatedDocument", _associateddocument, value))
                    {
                        string oldValue = _associateddocument;
                        _associateddocument = value;
                        OnPropertyChanged("AssociatedDocument", oldValue, value);
                    }
                }
            }
        }  private string _associateddocument = null;





        /// <summary>
        /// CrossStreet.
        /// </summary>
        public string CrossStreet
        {
            get { return _crossstreet; }
            set
            {
                if (_crossstreet != value)
                {
                    if (OnPropertyChanging("CrossStreet", _crossstreet, value))
                    {
                        string oldValue = _crossstreet;
                        _crossstreet = value;
                        OnPropertyChanged("CrossStreet", oldValue, value);
                    }
                }
            }
        }  private string _crossstreet = null;


        /// <summary>
        /// City.
        /// </summary>
        public string City
        {
            get { return _city; }
            set
            {
                if (_city != value)
                {
                    if (OnPropertyChanging("City", _city, value))
                    {
                        string oldValue = _city;
                        _city = value;
                        OnPropertyChanged("City", oldValue, value);
                    }
                }
            }
        }  private string _city = null;


        /// <summary>
        /// State.
        /// </summary>
        public string State
        {
            get { return _state; }
            set
            {
                if (_state != value)
                {
                    if (OnPropertyChanging("State", _state, value))
                    {
                        string oldValue = _state;
                        _state = value;
                        OnPropertyChanged("State", oldValue, value);
                    }
                }
            }
        }  private string _state = null;



        /// <summary>
        /// Country.
        /// </summary>
        public string Country
        {
            get { return _country; }
            set
            {
                if (_country != value)
                {
                    if (OnPropertyChanging("Country", _country, value))
                    {
                        string oldValue = _country;
                        _country = value;
                        OnPropertyChanged("Country", oldValue, value);
                    }
                }
            }
        }  private string _country = null;


        /// <summary>
        /// ConsultantID.
        /// </summary>
        public string ConsultantID
        {
            get { return _consultantID; }
            set
            {
                if (_consultantID != value)
                {
                    if (OnPropertyChanging("ConsultantID", _consultantID, value))
                    {
                        string oldValue = _consultantID;
                        _consultantID = value;
                        OnPropertyChanged("ConsultantID", oldValue, value);
                    }
                }
            }
        }  private string _consultantID = null;



        /// <summary>
        /// PostalCode.
        /// </summary>
        public string PostalCode
        {
            get { return _postalcode; }
            set
            {
                if (_postalcode != value)
                {
                    if (OnPropertyChanging("PostalCode", _postalcode, value))
                    {
                        string oldValue = _postalcode;
                        _postalcode = value;
                        OnPropertyChanged("PostalCode", oldValue, value);
                    }
                }
            }
        }  private string _postalcode = null;



        /// <summary>
        /// JobStatus.
        /// </summary>
        public string JobStatus
        {
            get { return _jobstatus; }
            set
            {
                if (_jobstatus != value)
                {
                    if (OnPropertyChanging("JobStatus", _jobstatus, value))
                    {
                        string oldValue = _jobstatus;
                        _jobstatus = value;
                        OnPropertyChanged("JobStatus", oldValue, value);
                    }
                }
            }
        }  private string _jobstatus = null;



        /// <summary>
        /// Date/time of Job Completion Date.
        /// </summary>
        public DateTime? JobCompletionDate
        {
            get { return _jobcompletiondate; }
            set
            {
                if (_jobcompletiondate != value)
                {
                    if (OnPropertyChanging("JobCompletionDate", _jobcompletiondate, value))
                    {
                        DateTime? oldValue = _jobcompletiondate;
                        _jobcompletiondate = value;
                        OnPropertyChanged("JobCompletionDate", oldValue, value);
                    }
                }
            }
        }  private DateTime? _jobcompletiondate = null;

        /// <summary>
        /// Job Expiry Date.
        /// </summary>
        public DateTime? JobExpiryDate
        {
            get { return _jobexpirydate; }
            set
            {
                if (_jobexpirydate != value)
                {
                    if (OnPropertyChanging("JobExpiryDate", _jobexpirydate, value))
                    {
                        DateTime? oldValue = _jobexpirydate;
                        _jobexpirydate = value;
                        OnPropertyChanged("JobExpiryDate", oldValue, value);
                    }
                }
            }
        }  private DateTime? _jobexpirydate = null;


        /// <summary>
        /// Date/time at which Job is posted
        /// </summary>
        public DateTime? JobPostedOn
        {
            get { return _jobpostedon; }
            set
            {
                if (_jobpostedon != value)
                {
                    if (OnPropertyChanging("JobPostedOn", _jobpostedon, value))
                    {
                        DateTime? oldValue = _jobpostedon;
                        _jobpostedon = value;
                        OnPropertyChanged("JobPostedOn", oldValue, value);
                    }
                }
            }
        }  private DateTime? _jobpostedon = null;



        /// <summary>
        /// Date/time at which Job will start
        /// </summary>
        public DateTime? JobStartedOn
        {
            get { return _jobStartedon; }
            set
            {
                if (_jobStartedon != value)
                {
                    if (OnPropertyChanging("JobStartedOn", _jobStartedon, value))
                    {
                        DateTime? oldValue = _jobStartedon;
                        _jobStartedon = value;
                        OnPropertyChanged("JobStartedOn", oldValue, value);
                    }
                }
            }
        }  private DateTime? _jobStartedon = null;


        /// <summary>
        /// Date/time at which Job will end
        /// </summary>
        public DateTime? JobEndedOn
        {
            get { return _jobEndedon; }
            set
            {
                if (_jobEndedon != value)
                {
                    if (OnPropertyChanging("JobEndedOn", _jobEndedon, value))
                    {
                        DateTime? oldValue = _jobEndedon;
                        _jobEndedon = value;
                        OnPropertyChanged("JobEndedOn", oldValue, value);
                    }
                }
            }
        }  private DateTime? _jobEndedon = null;


        /// <summary>
        /// AwardedBidID , to which the job is awarded.
        /// </summary>
        public int AwardedBidID
        {
            get { return _awardedBidID; }
            set
            {
                if (_awardedBidID != value)
                {
                    if (OnPropertyChanging("AwardedBidID", _awardedBidID, value))
                    {
                        int oldValue = _awardedBidID;
                        _awardedBidID = value;
                        OnPropertyChanged("AwardedBidID", oldValue, value);
                    }
                }
            }
        }  private int _awardedBidID = -1;


        /// <summary>
        /// True if the work status is required.
        /// </summary>
        public bool IsWorkStatusRequired
        {
            get { return _isWorkStatusRequired; }
            set
            {
                if (_isWorkStatusRequired != value)
                {
                    if (OnPropertyChanging("IsWorkStatusRequired", _isWorkStatusRequired, value))
                    {
                        bool oldValue = _isWorkStatusRequired;
                        _isWorkStatusRequired = value;
                        OnPropertyChanged("IsWorkStatusRequired", oldValue, value);
                    }
                }
            }
        }  private bool _isWorkStatusRequired = false;


        /// <summary>
        /// True if the job is featured.
        /// </summary>
        public bool IsFeatured
        {
            get { return _isfeatured; }
            set
            {
                if (_isfeatured != value)
                {
                    if (OnPropertyChanging("IsFeatured", _isfeatured, value))
                    {
                        bool oldValue = _isfeatured;
                        _isfeatured = value;
                        OnPropertyChanged("IsFeatured", oldValue, value);
                    }
                }
            }
        }  private bool _isfeatured = false;

        /// <summary>
        /// True if the featured job fees is given.
        /// </summary>
        public bool IsFeaturedFeesGiven
        {
            get { return _isFeaturedFeesGiven; }
            set
            {
                if (_isFeaturedFeesGiven != value)
                {
                    if (OnPropertyChanging("IsFeaturedFeesGiven", _isFeaturedFeesGiven, value))
                    {
                        bool oldValue = _isFeaturedFeesGiven;
                        _isFeaturedFeesGiven = value;
                        OnPropertyChanged("IsFeaturedFeesGiven", oldValue, value);
                    }
                }
            }
        }  private bool _isFeaturedFeesGiven = false;

        
        /// <summary>
        /// True if the job is visible.
        /// </summary>
        public bool JobVisibility
        {
            get { return _jobvisibility; }
            set
            {
                if (_jobvisibility != value)
                {
                    if (OnPropertyChanging("JobVisibility", _jobvisibility, value))
                    {
                        bool oldValue = _jobvisibility;
                        _jobvisibility = value;
                        OnPropertyChanged("JobVisibility", oldValue, value);
                    }
                }
            }
        }  private bool _jobvisibility = false;



        /// <summary>
        /// PKID of the BidCategory.
        /// </summary>
        public int BidCategoryID
        {
            get { return _bidcategoryID; }
            set
            {
                if (_bidcategoryID != value)
                {
                    if (OnPropertyChanging("BidCategoryID", _bidcategoryID, value))
                    {
                        int oldValue = _bidcategoryID;
                        _bidcategoryID = value;

                        OnPropertyChanged("BidCategoryID", oldValue, value);
                    }
                }
            }
        }  private int _bidcategoryID = -1;



        /// <summary>
        /// True iff the user has made this job archieved 
        /// </summary>
        public bool IsArchieved
        {
            get { return _isArchieved; }
            set
            {
                if (_isArchieved != value)
                {
                    if (OnPropertyChanging("IsArchieved", _isArchieved, value))
                    {
                        bool oldValue = _isArchieved;
                        _isArchieved = value;
                        OnPropertyChanged("IsArchieved", oldValue, value);
                    }
                }
            }
        }  private bool _isArchieved = false;




        /// <summary>
        /// True iff the Admin has made this Job Active (i.e. to be used in the application).
        /// </summary>
        public bool IsActive
        {
            get { return _isActive; }
            set
            {
                if (_isActive != value)
                {
                    if (OnPropertyChanging("IsActive", _isActive, value))
                    {
                        bool oldValue = _isActive;
                        _isActive = value;
                        OnPropertyChanged("IsActive", oldValue, value);
                    }
                }
            }
        }  private bool _isActive = false;

        #endregion

        #endregion

        #region Public Methods

        #region CreateNew

        /// <summary>
        /// Creates a new, empty JobCategory object.
        /// </summary>
        public static Job CreateNew()
        {
            Job obj = new Job();

            // Switch state to Added prior to initializing property values.
            obj.ObjState = ObjectState.Added;
            obj.JobPostedOn = DateTime.Now;
            obj.IsFeaturedFeesGiven = false;
            obj.IsActive = false;
            return (obj);
        }


        [MethodImpl(MethodImplOptions.Synchronized)]
        public static Job CreateNew(JobCollection collection)
        {
            Job obj = CreateNew();

            collection.Add(obj);

            return (obj);
        }

        #endregion

        #region GetAllJob

        /// <summary>
        /// Returns a collection of all Job.
        /// </summary>
        public static JobCollection GetAllJob()
        {
            JobsTableAdapter adapter = new JobsTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobsDataTable tbl = adapter.GetData(null);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobsRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        #region GetJobByID

        /// <summary>
        /// Returns an Job object for the specified 'JobID' or null if no Job with the specified parameter(s) exists.
        /// </summary>
        public static Job GetJobByID(string jobid)
        {
            JobsTableAdapter adapter = new JobsTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();
            dsJob.JobsDataTable tbl = adapter.GetData(jobid);

            if (tbl.Rows.Count == 1)
            {
                Job job = new Job();
                RelationalToObject(job, tbl.Rows[0]);
                return (job);
            }
            else if (tbl.Rows.Count > 1)
                throw new ApplicationException("Database integrity error: Specified 'userLogin' returned more than one User record.");

            return (null);
        }

        #endregion

        #region GetJobByJobIsActive

        /// <summary>
        /// Returns an Job object for the specified 'UserID' or null if no Job with the specified parameter(s) exists.
        /// </summary>
        public static JobCollection GetJobByJobIsActive(bool isactive)
        {
            JobsTableAdapter adapter = new JobsTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobsDataTable tbl = adapter.GetDataByJobIsActive(isactive);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobsRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        #region GetJobByUserID

        /// <summary>
        /// Returns an Job object for the specified 'UserID' or null if no Job with the specified parameter(s) exists.
        /// </summary>
        public static JobCollection GetJobByUserID(int userid)
        {
            JobsTableAdapter adapter = new JobsTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobsDataTable tbl = adapter.GetDataByUserID(userid);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobsRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        #region GetJobByConsultantID

        /// <summary>
        /// Returns an Job object for the specified 'ConsultantID' or null if no Job with the specified parameter(s) exists.
        /// </summary>
        public static JobCollection GetJobByConsultantID(string Consultantid)
        {
            JobsTableAdapter adapter = new JobsTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobsDataTable tbl = adapter.GetDataByConsultantID(Consultantid);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobsRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        //#region GetJobByJobCategoryID

        ///// <summary>
        ///// Returns an Job object for the specified 'JobCategoryID' or null if no Job with the specified parameter(s) exists.
        ///// </summary>
        //public static JobCollection GetJobByJobCategoryID(int jobcategoryid)
        //{
        //    JobsTableAdapter adapter = new JobsTableAdapter();
        //    adapter.Connection = AppSettings.GetDbConn();

        //    dsJob.JobsDataTable tbl = adapter.GetDataByJobCategoryID(jobcategoryid);

        //    JobCollection list = new JobCollection();

        //    if (tbl.Rows.Count > 0)
        //    {
        //        foreach (dsJob.JobsRow row in tbl.Rows)
        //        {
        //            Job job = new Job();
        //            RelationalToObject(job, row);
        //            list.Add(job);
        //        }
        //    }

        //    return (list);
        //}

        //#endregion

        #region GetJobSummaryByUserID

        /// <summary>
        /// Returns an Job object for the specified 'JobID' or null if no Job with the specified parameter(s) exists.
        /// </summary>
        public static JobCollection GetJobSummaryByUserID(int userid, int numberofrows, string jobstatus, bool isarchived)
        {
            JobSummaryTableAdapter adapter = new JobSummaryTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobSummaryDataTable tbl = adapter.GetJobSummary(userid, numberofrows, jobstatus, isarchived);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobSummaryRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        #region GetJobSummaryByConsultantID

        /// <summary>
        /// Returns collection of Job object.
        /// </summary>
        public static JobCollection GetJobSummaryByConsultantID(string Consultantid, int numberofrows, string jobstatus, bool isarchived)
        {
            JobSummaryTableAdapter adapter = new JobSummaryTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsJob.JobSummaryDataTable tbl = adapter.GetJobSummaryByConsultantID(Consultantid, numberofrows, jobstatus, isarchived);

            JobCollection list = new JobCollection();

            if (tbl.Rows.Count > 0)
            {
                foreach (dsJob.JobSummaryRow row in tbl.Rows)
                {
                    Job job = new Job();
                    RelationalToObject(job, row);
                    list.Add(job);
                }
            }

            return (list);
        }

        #endregion

        #region Update

        /// <summary>
        /// Updates the specified Job.
        /// </summary>
        public static void Update(Job obj)
        {
            bool updateJob = false;

            // Do not update invalid objects.
            if (!obj.Validate())
            {
                StringBuilder sb = new StringBuilder(2048);
                sb.Append("The object being updated has one or more invalid properties; the Update() operation for this object has been cancelled.\nError(s):");
                foreach (ValidationError err in obj.Errors)
                    sb.Append("\n* " + err.Element + ": " + err.Message);

                throw new InvalidObjectException(sb.ToString());
            }
            else
            {
                updateJob = (obj.ObjState != ObjectState.Unchanged);

                if (!updateJob)
                    return;
            }

            ObjectState originalObjectState = obj.ObjState;

            dsJob.JobsDataTable tbl = null;
            if (updateJob)
            {
                JobsTableAdapter adapter = new JobsTableAdapter();
                adapter.Connection = AppSettings.GetDbConn();

                tbl = new dsJob.JobsDataTable();
                dsJob.JobsRow row = tbl.NewJobsRow();
                ObjectToRelational(obj, tbl, row);

                adapter.Update(tbl);

                if (originalObjectState == ObjectState.Deleted)
                    obj = null;
                else RelationalToObject(obj, tbl.Rows[0]);
            }
        }

        #endregion

        #region Validate

        /// <summary>
        /// Validates the object based on its properties at the time of the call; updates the Errors property.
        /// </summary>
        public override bool Validate()
        {
            Errors.Clear();

            if (ObjState == ObjectState.Unchanged)
            {
                // By definition, unchanged objects are valid.
                return (true);
            }
            else if (ObjState == ObjectState.Uninitialized)
            {
                Errors.Add(new ValidationError("object", "Object is uninitialized.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else if ((ObjState == ObjectState.Deleted))
            {
                // Deleted items must have 'real' (i.e. non-negative, non-zero) key(s) to be valid.
                Errors.Add(new ValidationError("JobID", "Deleted object has an invalid PKID.", ValidationError.Severity.Error));

                // No need to proceed past this error.
                return (false);
            }
            else  // ObjState == Added | Modified
            {

                

            }

            return (Errors.Count == 0);
        }

        #endregion

        #region ToString

        /// <summary>
        /// User-friendly string represetation of this object.
        /// </summary>
        public override string ToString()
        {
            return (String.Format("Job: JobID={0}, UserID={1}", JobID, UserID_RK_tblRegisteredUsers));
        }

        #endregion

        #endregion

        #region Privates


        #endregion

    }

    /// <summary>
    /// Collection of 0 or more Job objects.
    /// </summary>

    public class JobCollection : List<Job>
    {
        #region Types

        public class UserComparer : IComparer<Job>
        {
            public int Compare(Job j1, Job j2)
            {
                return (String.Compare(j1.JobID.ToString(), j2.JobID.ToString()));
            }
        }

        #endregion

        #region Public Methods

        #region FindByJobID

        public Job FindByJobID(string jobID)
        {
            for (int ndx = 0; ndx < this.Count; ndx++)
                if (this[ndx].JobID == jobID)
                    return (this[ndx]);

            return (null);
        }

        #endregion

        #region FindJobByUserID

        /// <summary>
        /// Case insensitve compare.
        /// </summary>
        public Job FindJobByUserID(int userID)
        {
            for (int ndx = 0; ndx < this.Count; ndx++)
                if (this[ndx].UserID_RK_tblRegisteredUsers == userID)
                    return (this[ndx]);

            return (null);
        }

        #endregion

        #region FindJobByJobCategoryName

        /// <summary>
        /// Case insensitve compare.
        /// </summary>
        public int FindJobByJobCategoryName(string jobcategoryName)
        {
            int count=0;
            for (int ndx = 0; ndx < this.Count; ndx++)
                if (this[ndx].JobCategoryName == jobcategoryName)
                    count++;

            return (count);
        }

        #endregion

        #region FindJobByJobCategoryNameandJobStatus

        /// <summary>
        /// Case insensitve compare.
        /// </summary>
        public int FindJobByJobCategoryNameandJobStatus(string jobcategoryName, string jobstatus)
        {
            int count = 0;
            for (int ndx = 0; ndx < this.Count; ndx++)
                if ((this[ndx].JobCategoryName == jobcategoryName) && (this[ndx].JobStatus == jobstatus))
                    count++;

            return (count);
        }

        #endregion

        #region FindJobByJobSubCategoryNameandJobStatus

        /// <summary>
        /// Case insensitve compare.
        /// </summary>
        public int FindJobByJobSubCategoryNameandJobStatus(string jobsubcategoryName, string jobstatus)
        {
            int count = 0;
            for (int ndx = 0; ndx < this.Count; ndx++)
                if ((this[ndx].JobSubCategoryName == jobsubcategoryName) && (this[ndx].JobStatus == jobstatus))
                    count++;

            return (count);
        }

        #endregion

        #region FindByJobStatus

        public Job FindByJobStatus(string jobStatus)
        {
            for (int ndx = 0; ndx < this.Count; ndx++)
                if (this[ndx].JobStatus == jobStatus)
                    return (this[ndx]);

            return (null);
        }

        #endregion

        #endregion
    }
}
